package com.intelligentclass.services;

import com.intelligentclass.entity.Copy;
import com.intelligentclass.repositories.CopyRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CopyService {

    @Autowired
    private CopyRepository copyRepository;

    // 保存收藏记录
    public Copy saveCopy(Copy copy) {
        return copyRepository.save(copy);
    }

    // 删除收藏记录
    public void deleteCopy(Copy copy) {
        copyRepository.delete(copy);
    }

    // 查找所有收藏记录
    public List<Copy> findAllCopies() {
        return copyRepository.findAll();
    }

    // 根据 ID 查找收藏记录
    public Copy findById(int copyId) {
        return copyRepository.findById(copyId).orElse(null);
    }

    public Copy findByHostAndGuest(String host, String guest) {
        return copyRepository.findByCopyHostAndCopyGuest(host, guest);
    }

}
